﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;

namespace Diagram.DynamicDiagram
{
    public class DynamicDiagram : Grid
    {
        #region 构造函数
        public DynamicDiagram(double width, DataModel model)
        {
            initializeData(width, model);
            initializeGraphics();
            initializeHandler();
        }
        #endregion

        #region 属性
        // 图形数据
        private List<Column> _columnList;               // 存储数据列
        private ColumnScale _scale;                     // 刻度列

        private StackPanel _headPanel;                  // 表头 panel
        private StackPanel _bodyPanel;                  // Canvas Panel
        private ScrollViewer _bodyScrollViewer;         // body滚动条

        // 数据
        private DataModel _model;                       // 存储数据
        private double _width;                          // 整个图表宽度

        public List<Column> ColumnList
        {
            get { return _columnList; }
            set { _columnList = value; }
        }

        public ColumnScale Scale
        {
            get { return _scale; }
            set { _scale = value; }
        }

        public DataModel Model
        {
            get { return _model; }
            set { _model = value; }
        }

        public StackPanel HeadPanel
        {
            get { return _headPanel; }
            set { _headPanel = value; }
        }

        public StackPanel BodyPanel
        {
            get { return _bodyPanel; }
            set { _bodyPanel = value; }
        }
        #endregion

        #region 公共函数
        #endregion

        #region 私有函数
        private void initializeData(double width, DataModel model)
        {
            // 初始化基本数据
            _model = model;
            _width = width;

            // 初始化Scale列
            _scale = new ColumnScale(model);
            // 初始化数据列


        }

        private void initializeGraphics()
        {
            // 配置diagram显示属性
            RowDefinition header = new RowDefinition() { Height = new GridLength(_model.DefaultHeaderHeight) };
            RowDefinition body = new RowDefinition() { Height = new GridLength(_model.DefaultColumnHeight) };
            ColumnDefinition column = new ColumnDefinition() { Width = new GridLength(_width) };
            this.ColumnDefinitions.Add(column);
            this.RowDefinitions.Add(header);
            this.RowDefinitions.Add(body);

            _headPanel = new StackPanel() { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Center };
            _bodyPanel = new StackPanel() { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top };
            _bodyScrollViewer = new ScrollViewer() { HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden, VerticalScrollBarVisibility = ScrollBarVisibility.Auto};

            // 添加刻度列

            // 初始化数据列ScrollViewer
            //_columnScrollViewer = new ScrollViewer() { Width = };



        }

        private void initializeHandler()
        { 
            
        }
        #endregion

        #region 动态图形处理
        #endregion
    }
}
